#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

const int N = 10010, INF = 1e8;

int n;
int a[N];
int main()
{
    cin >> n;

    for (int i = 0; i < n; i++) cin >> a[i];

    int res = 0;
    for (int i = 0; i < n; i++)
    {
        int minv = INF, maxv = -INF;
        for (int j = i; j < n; j++)
        {
            minv = min(minv, a[j]);
            maxv = max(maxv, a[j]);
            if (maxv - minv == j - i) res++;
        }
    }

    cout << res << endl;
    return 0;
}